package com.example.eos.service;

import com.example.eos.bean.Label;
import com.example.eos.bean.ReturnInfo;
import com.example.eos.mapper.LabelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LabelService {

    private LabelMapper labelMapper;

    @Autowired
    public LabelService(LabelMapper labelMapper){
        this.labelMapper = labelMapper;
    }

    //查询标签列表
    public ReturnInfo getLabel(){
        return ReturnInfo.info3(labelMapper.findAll());
    }

    //查询标签列表（标签名）
    public ReturnInfo getLabelList(String labelname){
        return ReturnInfo.info2("成功",labelMapper.findListByLabelname(labelname));
    }

    //新建标签
    public ReturnInfo creatLabel(Label label, List<String> stringList){
        if(labelMapper.findByLabelname(label.getLabelname())!=null){
            stringList.add("该标签已存在");
            return ReturnInfo.info2("失败", stringList);
        }else {
            labelMapper.save(new Label(label.getLabelname()));
            return ReturnInfo.info2("成功", stringList);
        }
    }

    //删除标签
    public ReturnInfo deteleLabel(String labelid){
        if(labelMapper.findByLabelid(labelid)==null){
            return ReturnInfo.info1("失败");
        }else {
            labelMapper.deleteByLabelid(labelid);
            return ReturnInfo.info1("成功");
        }
    }

}
